package com.github.freewu.mvp.presenter;

import android.content.Intent;

import com.github.freewu.commons.http.HttpDataProcess;
import com.github.freewu.commons.http.HttpUtils;
import com.github.freewu.mvp.mvpInterface.MvpInterface;
import com.google.gson.Gson;

/**
 * 以http为主的访问控制器
 * Created by free on 16-7-29.
 */
public abstract class HttpPresenter<V extends MvpInterface.ViewInterface, P> extends Presenter<V> {
    protected P presenterInterface;

    protected HttpDataProcess<V> process;

    private Gson gson;

    public HttpPresenter(V mView) {
        super(mView);
    }

    @Override
    public void init(Intent intent) {
        presenterInterface=HttpUtils.getInstance().getRetrofit().create(getApiServerClass());

        process=new HttpDataProcess<V>(getView());

        gson=new Gson();
    }

    public abstract Class<P> getApiServerClass();

    @Override
    public void onDestroy() {
        HttpUtils.getInstance().cancelAll();

        super.onDestroy();
    }

    /**
     * 得到网络api接口
     * @return
     */
    protected P getApiServer(){
       return presenterInterface;
    }

    /**
     * 得到数据处理类
     * @return
     */
    public HttpDataProcess<V> getProcess() {
        return process;
    }
}
